//
//  YQAVManager.m
//  EPA--1
//
//  Created by lanou3g on 16/4/21.
//  Copyright © 2016年 刘永庆. All rights reserved.
//

#import "YQAVManager.h"

@interface YQAVManager ()
@property (nonatomic, strong) AVPlayer *player;
@end

@implementation YQAVManager
+ (instancetype)shareManger{
    static YQAVManager *avManger = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        avManger = [YQAVManager new];
        avManger.player = [[AVPlayer alloc]init];
    });
    return avManger;
}
- (void)play
{
    AVPlayerItem *item = self.itemArray[self.currentIndex];
    [self.player replaceCurrentItemWithPlayerItem:item];
    [self.player play];
}
- (void)pause {
    [self.player pause];
}
- (void)next {
    self.currentIndex++;
    if (self.currentIndex == self.itemArray.count) {
        self.currentIndex = 0;
    }
    [self play];
}
- (void)previous {
    self.currentIndex--;
    if (self.currentIndex < 0) {
        self.currentIndex = self.itemArray.count - 1;
    }
    [self play];
}
- (void)seekToTime:(CMTime)time
{
    [self.player seekToTime:time];
    
}
@end
